﻿using System;

namespace YourLastOptionsDialog.ViewModels.Options
{
    /// <summary>
    /// Contains properties common to all options, 
    /// as well as get and set accessors to the property values of the original source.
    /// </summary>
    public abstract class Option : ViewModelBase
    {
        private string _displayName;
        private string _description;
        private string _groupName;
        private int _displayOrder;

        /// <summary>
        /// Gets or sets the display name.
        /// </summary>
        public string DisplayName
        {
            get
            {
                return _displayName;
            }

            set
            {
                if (_displayName != value)
                {
                    _displayName = value;
                    RaisePropertyChanged("DisplayName");
                }
            }
        }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        public string Description
        {
            get
            {
                return _description;
            }

            set
            {
                if (_description != value)
                {
                    _description = value;
                    RaisePropertyChanged("Description");
                }
            }
        }

        /// <summary>
        /// Gets or sets the name of the group used to group the options in the UI.
        /// </summary>
        public string GroupName
        {
            get
            {
                return _groupName;
            }

            set
            {
                if (_groupName != value)
                {
                    _groupName = value;
                    RaisePropertyChanged("GroupName");
                }
            }
        }

        /// <summary>
        /// Gets or sets the display order which determines the order of options within a group.
        /// </summary>
        public int DisplayOrder
        {
            get
            {
                return _displayOrder;
            }

            set
            {
                if (_displayOrder != value)
                {
                    _displayOrder = value;
                    RaisePropertyChanged("DisplayOrder");
                }
            }
        }

        /// <summary>
        /// Gets or sets the get accessor that can be used to retrieve the original option value 
        /// from the source.
        /// </summary>
        public Func<object> GetAccessor
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the set accessor that can be used to write back the option value
        /// to the originating source.
        /// </summary>
        public Action<object> SetAccessor
        {
            get;
            set;
        }
    }
}